package br.com.dallas.util.manipular;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import sun.misc.BASE64Encoder;
import br.com.dallas.util.validar.ValidarObjeto;

public final class Criptografar
{
	public static String criptografa(String mensagem)
	{
		MessageDigest digest = null;
		BASE64Encoder encoder = null;
		try
		{
			if (ValidarObjeto.isStringValida(mensagem))
			{
				digest = MessageDigest.getInstance("MD5");
				digest.update(mensagem.getBytes());
				encoder = new BASE64Encoder();
				return encoder.encode(digest.digest());
			}
		}
		catch(NoSuchAlgorithmException e)
		{	
			e.printStackTrace();
		}
		finally
		{
			if (digest != null)
				digest = null;
			
			if (encoder != null)
				encoder = null;
		}
		return "";
	}
}
